package cn.jiyun.controller;


import cn.jiyun.common.config.Result;
import cn.jiyun.entity.GoodsList;
import cn.jiyun.service.IGoodsListService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-21
 */
@RestController
@RequestMapping("/xm-goods/goods-list")
public class GoodsListController {
    @Autowired
    private IGoodsListService goodsListService;

    @RequestMapping("/test")
    public Result test(){
        String[] add={"全部", "1111", "2222", "3333", "4444"};
        return Result.ok(add);
    }

//    商品分页查询
    @RequestMapping("/findpage")
    public Result findpage(Integer current, Integer pageSize, @RequestBody GoodsList goodsList){
        System.out.println(goodsList+"--------------------------------");
        Page<GoodsList> page = goodsListService.findpage(current,pageSize, goodsList);
        System.out.println("111111111111111111111111111111111111"+page.getRecords());
        return Result.ok(page);
    }
//    商品id查询
    @RequestMapping("/findbyid")
    public Result findbyid(Integer id){
        return Result.ok(goodsListService.getById(id));
    }
    @RequestMapping("/findbyid2/{id}")
    public GoodsList findbyid2(@PathVariable Integer id){
        return goodsListService.getById(id);
    }
//    套餐gid查询
    @RequestMapping("/findbyidcombo")
    public Result findbyidcombo(Integer id){
        return Result.ok(goodsListService.findbyidcombo(id));
    }
//    审核修改
    @RequestMapping("/update")
    public Result update(@RequestBody GoodsList goodsList){
        goodsList.setUpdatetime(LocalDateTime.now());
        goodsListService.updateById(goodsList);
        return Result.ok();
    }
    @RequestMapping("/update2")
    public void update2(@RequestBody GoodsList goodsList){
        goodsList.setUpdatetime(LocalDateTime.now());
        goodsListService.updateById(goodsList);
    }
//    根据分类查询餐品
    @RequestMapping("/findbyclassification")
    public Result findbyclassification(String classification){
        return Result.ok(goodsListService.list(new LambdaQueryWrapper<GoodsList>().eq(GoodsList::getClassification, classification)));
    }
}
